Skip to main content

刚体 Rigidbody2-new

使用刚体后,对象将立即响应重力。如果还添加了一个或多个碰撞体组件,则游戏对象会因为碰撞而发生移动;
不应试图借助脚本通过改变变换属性【比如位置、旋转】来移动游戏对象,应该使用施加力的方式来推动游戏对象并让物理引擎计算结果。

using System.Collections;

using System.Collections.Generic;

using UnityEngine;



public class box : MonoBehaviour

{



RigidBody r;

// Start is called before the first frame update

void Start()

{

r = GetComponent<RigidBody>();

}



// Update is called once per frame

void Update()

{

float x = Input.GetComponent("Horizontal");

float y = Input.GetComponent("V");

float z = Input.getComponent("vertical");

Vertical3 f = new Vertical3(x, 0, z);

r.addForce(f*3); //给r施加力

}

}

![[Pasted image 20220922154725.png]]![[Pasted image 20220922154725.png]](assets/Pasted image 20220922154725.png)